package com.bw.module_house.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.coroutine.CoroutineHelper
import com.bw.lib_common.vm.BaseViewModel2
import com.bw.module_house.model.HouseEntity
import com.bw.module_house.repo.HouseRepo
import kotlinx.coroutines.launch
/**
 * 智慧园区-03-房源信息V1.1-史建军-20250514
 */
class HouseViewModel :BaseViewModel2<HouseRepo>(){
    val houseSuccess by lazy { MutableLiveData<List<HouseEntity>>() }
    val houseIdSuccess by lazy { MutableLiveData<List<HouseEntity>>() }

    fun getHouseList(){
        CoroutineHelper.mViewModelScope.launch (CoroutineHelper.mDispatcher){
            val result=mRepository.getHouseList()
            if (result.code==200){
                houseSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue(result.message)
            }
        }
    }
    fun getHouseListById(id:Int){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result=mRepository.getHouseListById(id)
            if (result.code==200){
                houseIdSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue(result.message)
            }
            }
        }
    fun getHouseListSearch(keyword:String){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result=mRepository.getHouseListSearch(keyword)
            if (result.code==200){
                houseSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue(result.message)
            }
        }
    }




    override fun createRepository(): HouseRepo = HouseRepo()
}